﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace SalomonWebsite
{
    public partial class ProCat : System.Web.UI.Page
    {
        public string strCon = Global.Connection;
        public string ImageWeb = Global.ImageWeb;
        public int ParPKID;
        public int PKID;
        public string Val = "";

        public string catName = "";
        public string description = "";

        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                if (Request["parid"] != null && Request["parid"] != "" && Request["pkid"] != null && Request["pkid"] != "" && Request["val"] != null && Request["val"] != "")
                {
                    ParPKID = Convert.ToInt32(Request["parid"]);
                    PKID = Convert.ToInt32(Request["pkid"]);
                    Val = Request["val"].ToString();

                    this.PageNote.PKID = PKID;
                    this.PageNote.ParPKID = ParPKID;
                    this.CatAd.ParPKID = ParPKID;

                    this.CatTree.PKID = PKID;
                    this.CatTree.ParPKID = ParPKID;

                    DataTable dtCat = new DataTable();
                    dtCat = Bll.Category.Single(strCon, PKID);
                    if (dtCat.Rows.Count == 1)
                    {
                        DataRow[] drs = dtCat.Select(" [CatCode] = '" + Val + "'");
                        if (drs.Length == 1)
                        {
                            catName = drs[0]["CatName"].ToString();
                            description = drs[0]["Description"].ToString();

                            GetCatList(PKID);
                        }
                        else
                        {
                            Response.Redirect("FileNotFound.aspx");
                        }
                    }
                    else
                    {
                        Response.Redirect("FileNotFound.aspx");
                    }
                }
                else
                {
                    Response.Redirect("FileNotFound.aspx");
                }
                
            }
        }


        //Find Salomon on
        protected void GetCatList(int parID)
        {
            DataTable dt = Bll.Category.MULTIPLE(strCon,parID);
            if (dt != null && dt.Rows.Count > 0)
            {
                this.rpCategory.DataSource = dt.DefaultView;
                this.rpCategory.DataBind();
                dt.Dispose();
            }
        }

       

    }
}
